#!/usr/bin/env python3
# coding=utf-8


import os
import sys
import shlex
import time
import datetime
import re

import configparser
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent

sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))

from task import pull_sshkey
from task import ssh_cmd
from utils.custom_argparse import parse_args
from utils.custom_log import log_start
logger = log_start('main')




if __name__ == '__main__':
    # logger.error("test")
    if len(sys.argv) == 1:
        """ 如果没有传参则打印帮助信息 """
        sys.argv.append("--help")
        parse_args()
        sys.exit(0)


    configfile = os.path.join(BASE_DIR, 'config.ini')
    cfg = configparser.ConfigParser()
    cfg.read(configfile)
    cfg.sections()

    params = parse_args()  # 获取传入的参数

    if params.pullkey:
        pull_sshkey.exec_cmd(params.sshkey,params.username,params.password,params.port)
    else:
        ssh_cmd.exec_cmd(params.sshkey,params.username,params.password,params.port,params.cmd,show=params.show)


        

    # res = cfg['kong_servers']['host']
    # print(re.split('[,;]',res))
    # res = cfg['gateway_servers']['host']
    # print(re.split('[,;]',res))